from wtforms import StringField, SelectMultipleField, IntegerField
from wtforms.validators import DataRequired, EqualTo

from apps.a_common.constants import SKILL_CHOICE
from apps.a_common.request import MyFlaskForm, ArrayField


class LoginForm(MyFlaskForm):
    username = StringField('用户名', [DataRequired('用户名不能为空')])
    password = StringField("密码", [DataRequired(u"密码不能为空")])


class SignUpForm(LoginForm):
    confirm_password = StringField("密码", [DataRequired(u"密码不能为空"), EqualTo("password", "两次密码不一致")])


class UserInfoBaseForm(MyFlaskForm):
    password = StringField("密码")
    nickname = StringField('用户昵称')
    first_name = StringField('姓')
    last_name = StringField('名')
    sex = IntegerField('性别')
    skills = SelectMultipleField('技能', choices=SKILL_CHOICE, coerce=int)


class UserInfoEditorForm(UserInfoBaseForm):
    avatar = StringField('头像')
    work_experience = StringField('工作经历')


class PermissionEditorForm(MyFlaskForm):
    name = StringField('权限的名字', [DataRequired('权限的名字不能为空')])
    type = IntegerField('权限的类型', [DataRequired('权限的类型不能为空')])


class PermissionGroupEditorForm(MyFlaskForm):
    name = StringField('权限组的名字', [DataRequired('权限组的名字不能为空')])
    user_id_list = ArrayField('用户id的列表', coerce=int)
    permission_id_list = ArrayField('权限id的列表', coerce=int)


class UserSearchForm(MyFlaskForm):
    skills = SelectMultipleField('技能', choices=SKILL_CHOICE, coerce=int)
    project_id = IntegerField('项目的id')
